home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Tools & Apps / Testing & Debugging / TV-Man Package / With Source Version / Source / TV-Man.Video.c < prev   
Encoding:
C/C++ Source or Header  |  1991-11-13  |  15.3 KB  |  551 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------
  2. #
  3. #    TV-Man.Video.c
  4. #
  5. #    Copyright © Apple Computer, Inc. 1989-1990
  6. #    All rights reserved.
  7. #
  8. #
  9. #
  10. #    All the pertinent code which provides the video patterns are found in this file.
  11. #    
  12. #    In order to have an evironment which predictable events happen several definitions
  13. #    must be established. The most critical is in the file architecture. Each functional
  14. #    block will have its own source and header file. The main project file,  in this
  15. #    case TV-Man, will have its header file included with all other files. This will
  16. #    allow for global constants. The utility source file shall contain functions that
  17. #    are general purpose in nature and that can be used by all other functions. These
  18. #    are intended not to be application or major block specific. In order for this to be 
  19. #    accomodated all functions in the utility source file must use only the information
  20. #    that is passed to them or information that can be gleaned from the system via
  21. #    toolbox calls. There will be no header file associated with the utility file as this
  22. #    will destroy the intent of the utilities.
  23. #
  24. #    There are several files which contain information which is global in nature .These
  25. #    file are included in the main project header file. They are: x.Errors.h, x.Ext.h,
  26. #    x.Protos.h, x.Menus.h. The reason for containing them in seperate files is one of
  27. #    convienience and accesability. 
  28. #
  29. #
  30. #    Revision Log:
  31. #    
  32. #        11-05-91    RGK        Added the menu items for single color screens
  33. #        04-26-91    RGK        Creation
  34. #
  35. #
  36. ------------------------------------------------------------------------------*/
  37.  
  38.  
  39. /*------------------------------------------------------------------------------*/
  40. /* This is a list of all local includes necessary for this pregram.    */
  41.  
  42. #include "TV-Man.h"
  43. #include "TV-Man.Video.h"
  44.  
  45.  
  46.  
  47. /*------------------------------------------------------------------------------*/
  48. /*    This draws the Test Pattern which is the display shown at the beginning  */
  49.  
  50. void DrawTestPattern(window)
  51. WindowPtr    window;
  52. {
  53.     Rect        box;
  54.     short        vcenter, hcenter, offset, space, width, ringcount;
  55.     TPValuesHdl    TPVHdl;
  56.     
  57.     TPVHdl = (TPValuesHdl)GetResource('tpat',rTestPattern);
  58.     if((TPVHdl == nil) || (ResError() != noErr)) 
  59.     {
  60.         Error(eMinor, eMinorRsrc);
  61.         gVideoPattern = gLastVideoPattern;        /* reset to previous pattern    */
  62.         InvalRect(&window->portRect);            /* invalidate entire window  */
  63.     }
  64.     else
  65.     {
  66.         PenSize((*TPVHdl)->LineWidth, (*TPVHdl)->LineWidth);
  67.         ForeColor((*TPVHdl)->ForeGColor);
  68.         BackColor((*TPVHdl)->BackGColor);
  69.         EraseRect(&(window->portRect));        /* this forces a full window to set the background    */
  70.     
  71. /*    the next two lines are just for read ability later    */
  72.  
  73.         width = (*TPVHdl)->LineWidth;
  74.         space = (*TPVHdl)->SpaceWidth;    
  75.         
  76.         
  77.         WhereCenter(window, &hcenter, &vcenter);
  78.         
  79.         
  80. /*    draw a vertical line remember to subtract out 1/2 the line width to adjust for
  81.         calculation from the center of the line    */
  82.     
  83.         MoveTo(hcenter - (width/2), window->portRect.top);
  84.         LineTo(hcenter - (width/2), window->portRect.bottom);
  85.         
  86.         
  87. /*    draw a horizontal line    */
  88.     
  89.         MoveTo(window->portRect.left, vcenter - (width/2));
  90.         LineTo(window->portRect.right, vcenter - (width/2));
  91.         
  92.         
  93. /*    now the upper left to lower right diagonal*/
  94.     
  95.         MoveTo(window->portRect.left - (width/2), window->portRect.top - (width/2));
  96.         LineTo(window->portRect.right - (width/2), window->portRect.bottom - (width/2));
  97.         
  98.         
  99. /*    now the other diagonal */
  100.     
  101.         MoveTo(window->portRect.left - (width/2), window->portRect.bottom - (width/2));
  102.         LineTo(window->portRect.right - (width/2), window->portRect.top - (width/2));
  103.         
  104.         
  105. /*    This next bit draws concentric circles about the center of the window. The variable
  106.     'space' determines the number of pixels between each ring. The variable 'stop' determines
  107.     the number of circles by calculating the vertical width of the window and seeing how many
  108.     rings of the width 'space' there can be. The loop then draws the rings.    */
  109.         
  110.         PenSize((*TPVHdl)->RingWidth, (*TPVHdl)->RingWidth);
  111.         width = (*TPVHdl)->RingWidth;
  112.         ringcount = 0;
  113.         offset = space + width;
  114.         
  115.         while (ringcount < ((window->portRect.bottom - window->portRect.top)/2)
  116.                                     /(space + width))
  117.         {
  118.             SetRect(&box, hcenter - offset,
  119.                     vcenter - offset, hcenter + offset,
  120.                     vcenter + offset);
  121.             FrameOval(&box);
  122.             offset = offset + space + width;
  123.             ringcount = ringcount + 1;
  124.         }
  125.     }
  126.     ReleaseResource((Handle)TPVHdl);
  127. }/* DrawTestPattern */
  128.  
  129.  
  130.  
  131.  
  132. /*------------------------------------------------------------------------------*/
  133. /*    Do the Standard Color Bars       */
  134.  
  135. void DrawColorBars(window)
  136. WindowPtr    window;
  137. {
  138.     short            offset = 0;
  139.     short            count = 0;
  140.     short            width;
  141.     Rect            bar;
  142.     PaletteHandle    PaletteHdl;
  143.  
  144.  
  145.     PaletteHdl = GrabPalette(window, ColorDepth, COLOR);
  146.     width = SizeVBar(window, CBarCount);    /*    Only 16 bars for this display    */
  147.     
  148. /*    This loop gets the color pointed to and paints the calculated bar with it    */
  149.  
  150.     while (offset < window->portRect.right)
  151.     {
  152.         SetRect( &bar,    window->portRect.left + offset, window->portRect.top, 
  153.                         window->portRect.left + width + offset, window->portRect.bottom);
  154.         offset = window->portRect.left + width + offset;
  155.         PmForeColor(count);
  156.         PaintRect(&bar);
  157.         count = count + 1;
  158.     }
  159.     DisposePalette(PaletteHdl);
  160. }/* DrawColorBars */
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167. /*------------------------------------------------------------------------------*/
  168. /*    The next four functions are just set up the color parameter for
  169.     the call to tdraw the screen one color    */
  170.  
  171. void    DrawRedScreen(window)
  172. WindowPtr    window;
  173. {
  174.     DrawSingleColor(window, RedScreenCol);
  175. }
  176. /* DrawRedScreen */
  177.  
  178.  
  179. void    DrawGreenScreen(window)
  180. WindowPtr    window;
  181. {
  182.     DrawSingleColor(window, GreenScreenCol);
  183. }
  184. /* DrawGreenScreen */
  185.  
  186.  
  187. void    DrawBlueScreen(window)
  188. WindowPtr    window;
  189. {
  190.     DrawSingleColor(window, BlueScreenCol);
  191. }
  192. /* DrawBlueScreen */
  193.  
  194.  
  195. void    DrawWhiteScreen(window)
  196. WindowPtr    window;
  197. {
  198.     DrawSingleColor(window, WhiteScreenCol);
  199. }
  200. /* DrawwhiteScreen */
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207. /*------------------------------------------------------------------------------*/
  208. /*    Color the screen one color       */
  209.  
  210. void DrawSingleColor(window, index)
  211. WindowPtr    window;
  212. short        index;
  213. {
  214.     short            offset = 0;
  215.     short            width;
  216.     Rect            bar;
  217.     PaletteHandle    PaletteHdl;
  218.  
  219.  
  220.     PaletteHdl = GrabPalette(window, ColorDepth, COLOR);
  221.     width = SizeVBar(window, 1);            /*    Only 1 bar for this display    */
  222.     
  223. /*    This loop gets the color pointed to and paints the calculated bar with it    */
  224.  
  225.     while (offset < window->portRect.right)
  226.     {
  227.         SetRect( &bar,    window->portRect.left + offset, window->portRect.top, 
  228.                         window->portRect.left + width + offset, window->portRect.bottom);
  229.         offset = window->portRect.left + width + offset;
  230.         PmForeColor(index);
  231.         PaintRect(&bar);
  232.     }
  233.     DisposePalette(PaletteHdl);
  234. }/* DrawSingleColor */
  235.  
  236.  
  237.  
  238. /*------------------------------------------------------------------------------*/
  239. /*    Do the Gray scale from light to dark    */
  240.  
  241. void DrawGrayScaleLD(window)
  242. WindowPtr    window;
  243. {
  244.     short            offset = 0;
  245.     short            colorindx = 1;
  246.     short            width, depth, barcount, *resourcePtr, **resourceHdl;
  247.     Rect            bar;
  248.     PaletteHandle    PaletteHdl;
  249.  
  250.  
  251.     resourceHdl = (short**)GetResource('gbrs',rGrayValues);
  252.     if((resourceHdl == nil) || (ResError() != noErr)) 
  253.     {
  254.         Error(eMinor, eMinorRsrc);
  255.         gVideoPattern = gLastVideoPattern;        /* reset to previous pattern    */
  256.         InvalRect(&window->portRect);            /* invalidate entire window  */
  257.     }
  258.     else
  259.     {
  260.         depth = **resourceHdl;
  261.         resourcePtr = *resourceHdl;
  262.         barcount = *(resourcePtr + 1);
  263.         ReleaseResource((Handle)resourceHdl);
  264.         
  265.         PaletteHdl = GrabPalette(window, depth, GRAY);
  266.         width = SizeVBar(window, barcount);
  267.         colorindx = 1;
  268.     
  269. /*    This loop paints the calculated bar with it    */
  270.     
  271.         while (offset < window->portRect.right)
  272.         {
  273.             SetRect( &bar,    window->portRect.left + offset, window->portRect.top, 
  274.                             window->portRect.left + width + offset, window->portRect.bottom);
  275.             offset = window->portRect.left + width + offset;
  276.             PmForeColor(colorindx - 1);
  277.             PaintRect(&bar);
  278.             if(depth/barcount < 1) colorindx = colorindx + 1;
  279.             else colorindx = colorindx + (depth/(barcount - 1));
  280.             if(colorindx > depth) colorindx = 1;
  281.         }
  282.     }
  283.     DisposePalette(PaletteHdl);
  284. }/* DrawGrayScaleLD */
  285.  
  286.  
  287.  
  288.  
  289. /*------------------------------------------------------------------------------*/
  290. /*    Do the Gray scale from dark to light    */
  291.  
  292. void DrawGrayScaleDL(window)
  293. WindowPtr    window;
  294. {
  295.     short            offset = 0;
  296.     short            colorindx = 1;
  297.     short            width, depth, barcount, *resourcePtr, **resourceHdl;
  298.     Rect            bar;
  299.     PaletteHandle    PaletteHdl;
  300.  
  301.  
  302.     resourceHdl = (short**)GetResource('gbrs',rGrayValues);
  303.     if((resourceHdl == nil) || (ResError() != noErr)) 
  304.     {
  305.         Error(eMinor, eMinorRsrc);
  306.         gVideoPattern = gLastVideoPattern;        /* reset to previous pattern    */
  307.         InvalRect(&window->portRect);            /* invalidate entire window  */
  308.     }
  309.     else
  310.     {
  311.         depth = **resourceHdl;
  312.         resourcePtr = *resourceHdl;
  313.         barcount = *(resourcePtr + 1);
  314.         ReleaseResource((Handle)resourceHdl);
  315.     
  316.         PaletteHdl = GrabPalette(window, depth, GRAY);
  317.         width = SizeVBar(window, barcount);
  318.         colorindx = depth;
  319.     
  320. /*    This loop paints the calculated bar with it    */
  321.     
  322.         while (offset < window->portRect.right)
  323.         {
  324.             SetRect( &bar,    window->portRect.left + offset, window->portRect.top, 
  325.                             window->portRect.left + width + offset, window->portRect.bottom);
  326.             offset = window->portRect.left + width + offset;
  327.             PmForeColor(colorindx - 1);
  328.             PaintRect(&bar);
  329.             if(depth/barcount < 1) colorindx = colorindx - 1;
  330.             else colorindx = colorindx - (depth/(barcount - 1));
  331.             if(colorindx < 1) colorindx = depth;
  332.         }
  333.     }
  334.     DisposePalette(PaletteHdl);
  335. }/* DrawGrayScaleDL */
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.  
  343.  
  344. /*------------------------------------------------------------------------------*/
  345. /*    This draws vertical lines across the screen  */
  346.  
  347. void DrawVertLines(window)
  348. WindowPtr    window;
  349. {
  350.     short        location, space, line;
  351.     LNValuesHdl    LNVHdl;
  352.  
  353.         
  354.     LNVHdl = (LNValuesHdl)GetResource('lnes',rVLines);
  355.     if((LNVHdl == nil) || (ResError() != noErr)) 
  356.     {
  357.         Error(eMinor, eMinorRsrc);
  358.     }
  359.     else
  360.     {
  361.         ForeColor((*LNVHdl)->LForeGColor);
  362.         BackColor((*LNVHdl)->LBackGColor);
  363.         EraseRect(&(window->portRect));        /* this forces a full window redraw to set the background    */
  364.     
  365.         space = (*LNVHdl)->LBackGCWidth;        /*    just for read ability later    */
  366.         line = (*LNVHdl)->LForeGCWidth;        /*    just for read ability later as well    */
  367.         PenSize((*LNVHdl)->LForeGCWidth, (*LNVHdl)->LForeGCWidth);
  368.         
  369. /*    This next bit draws vertical lines through the window. The variable
  370.     'space' determines the number of pixels between each line. The variable
  371.     'stop' determines the number of lines by calculating the  width of the
  372.     window and seeing how many lines of the combined width 'space'and the
  373.     darkcolor width there can be. The for loop then draws the lines.    */
  374.         
  375.         for(location = window->portRect.left + space;
  376.             location < window->portRect.right;
  377.             location = location + space + line)
  378.         {
  379.             MoveTo(window->portRect.left + location, window->portRect.top);
  380.             LineTo(window->portRect.left + location, window->portRect.bottom);
  381.         }
  382.     }
  383.     ReleaseResource((Handle)LNVHdl);
  384. }/* DrawVertLines */
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392. /*------------------------------------------------------------------------------*/
  393. /*    This draws horizontal lines across the screen  */
  394.  
  395. void DrawHorzLines(window)
  396. WindowPtr    window;
  397. {
  398.     short        location, space, line;
  399.     LNValuesHdl    LNVHdl;
  400.  
  401.  
  402.     LNVHdl = (LNValuesHdl)GetResource('lnes',rVLines);
  403.     if((LNVHdl == nil) || (ResError() != noErr)) 
  404.     {
  405.         Error(eMinor, eMinorRsrc);
  406.         gVideoPattern = gLastVideoPattern;        /* reset to previous pattern    */
  407.         InvalRect(&window->portRect);            /* invalidate entire window  */
  408.     }
  409.     else
  410.     {
  411.         ForeColor((*LNVHdl)->LForeGColor);
  412.         BackColor((*LNVHdl)->LBackGColor);
  413.         EraseRect(&(window->portRect));        /* this forces a full window redraw to set the background    */
  414.     
  415.         space = (*LNVHdl)->LBackGCWidth;        /*    just for read ability later    */
  416.         line = (*LNVHdl)->LForeGCWidth;        /*    just for read ability later as well    */
  417.         PenSize((*LNVHdl)->LForeGCWidth, (*LNVHdl)->LForeGCWidth);
  418.         
  419. /*    This next bit draws horizontal lines through the window. The variable
  420.     'space' determines the number of pixels between each line. The variable
  421.     'stop' determines the number of lines by calculating the height of the
  422.     window and seeing how many lines of the combined width 'space' and the
  423.     darkcolor width there can be. The for loop then draws the lines.    */
  424.         
  425.         for(location = window->portRect.top + space;
  426.             location < window->portRect.bottom;
  427.             location = location + space + line)
  428.         {
  429.             MoveTo(window->portRect.left, window->portRect.top + location);
  430.             LineTo(window->portRect.right, window->portRect.top + location);
  431.         }
  432.     }
  433.     ReleaseResource((Handle)LNVHdl);
  434. }/* DrawHorzLines */
  435.  
  436.  
  437.  
  438.  
  439. /*------------------------------------------------------------------------------*/
  440.  
  441. void DrawLineBurst(window)
  442. WindowPtr    window;
  443. {
  444.     short        location, space, line, count;
  445.     LBurstHdl    ResourceHdl;
  446.  
  447.  
  448.     ResourceHdl = (LBurstHdl)GetResource('lbst',rLineBurst);
  449.     if((ResourceHdl == nil) || (ResError() != noErr)) 
  450.     {
  451.         Error(eMinor, eMinorRsrc);
  452.         gVideoPattern = gLastVideoPattern;        /* reset to previous pattern    */
  453.         InvalRect(&window->portRect);            /* invalidate entire window  */
  454.     }
  455.     else
  456.     {
  457.         ForeColor((*ResourceHdl)->BarColor);
  458.         BackColor((*ResourceHdl)->BackGColor);
  459.         EraseRect(&(window->portRect));        /* this forces a full window redraw to set the background    */
  460.     
  461.         space = (*ResourceHdl)->BarSpace;        /*    just for read ability later    */
  462.         line = (*ResourceHdl)->BarWidth;        /*    just for read ability later as well    */
  463.         PenSize((*ResourceHdl)->BarWidth, (*ResourceHdl)->BarWidth);
  464.         location = window->portRect.left + space;
  465.         
  466. /*    This next bit draws verticlal lines through the window. The variable
  467.     'space' determines the number of pixels between each line.     */
  468.         
  469.         for(count = 0;
  470.             count < (*ResourceHdl)->BarCount;
  471.             count = count + 1)
  472.         {
  473.             MoveTo(window->portRect.left + location, window->portRect.top);
  474.             LineTo(window->portRect.left + location, window->portRect.bottom);
  475.             location = location + space + line;
  476.         }
  477.     }
  478.     ReleaseResource((Handle)ResourceHdl);
  479. }/* DrawLineBurst */
  480.  
  481.  
  482.  
  483.  
  484.  
  485. /*------------------------------------------------------------------------------*/
  486. /*    Locate the center of the appointed window. The origonal sizing of the
  487.     window should make sure of an even value of window width and height */
  488.  
  489. void WhereCenter(window, hcenter, vcenter)
  490. WindowPtr    window;
  491. short        *hcenter, *vcenter;
  492. {
  493.     *hcenter = (window->portRect.right - window->portRect.left)/2;
  494.     *vcenter = (window->portRect.bottom - window->portRect.top)/2;
  495. }/* WhereCenter */
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502. /*------------------------------------------------------------------------------*/
  503. /*    return the width value of the bars that divide the window
  504.     by the passed 'number' of bars    */
  505.  
  506. short SizeVBar(window,number)
  507. WindowPtr    window;
  508. short        number;
  509. {
  510. short         width;
  511.  
  512.     width = (window->portRect.right - window->portRect.left)/number;
  513.     if( width < 1) return 1;
  514.     else return width;
  515. }/* SizeVBar */
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523. /*------------------------------------------------------------------------------*/
  524. /*    This function sets up and returns the handle a palette. The request is made by
  525.     passing the pixel depth. This is the number of colors or shades of gray
  526.     available. A boolean value is also necessary which determines whether color
  527.     palettes or gray scale palettes are to be used.    */
  528.     
  529. PaletteHandle GrabPalette(window, depth, type)
  530. WindowPtr    window;
  531. short        depth;
  532. Boolean        type;
  533.  
  534. {
  535. PaletteHandle    PaletteHdl;
  536.  
  537.     if(type == GRAY)
  538.     {
  539.         if(depth == 256) PaletteHdl = GetNewPalette(rGPal8);
  540.         else PaletteHdl = GetNewPalette(rGPal4);
  541.     }
  542.     else PaletteHdl = GetNewPalette(rColorPal);
  543.     NSetPalette(window, PaletteHdl, pmNoUpdates);
  544.     FlushEvents(everyEvent,0);
  545.     return PaletteHdl;
  546. };/* GrabPalette */
  547.  
  548.  
  549.  
  550.  
  551.